package com.central.apps.controller;

import com.central.app.service.HandlerService;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/preservation")
@Slf4j
public class preservationController {
    @Autowired private HandlerService handlerService;
    @PostMapping("/preservationCon")

    public Map<String,Object> preservation (@RequestBody List<Map<String, Object>> params) throws Exception {
        if (CollectionUtils.isNotEmpty(params)){
            String code="0";
            for (int i =0;i<params.size();i++){
                Map<String, Object> map = params.get(i);
                String supplierno = MapUtils.getString(map, "supplierno");
                String advisupplier = MapUtils.getString(map, "advisupplier");
                String contacts = MapUtils.getString(map, "contacts");
                String phone = MapUtils.getString(map, "phone");
                Integer promptness = MapUtils.getInteger(map, "promptness");
                Integer passrate = MapUtils.getInteger(map, "passrate");
                Integer id = MapUtils.getInteger(map, "id");
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("supplierno",supplierno);
                hashMap.put("advisupplier",advisupplier);
                hashMap.put("contacts",contacts);
                hashMap.put("phone",phone);
                hashMap.put("promptness",promptness);
                hashMap.put("passrate",passrate);
                hashMap.put("status",supplierno);
                hashMap.put("prsupplierid",id);
                handlerService.insert("gq_prsupplier",hashMap);
            }
            String msg ="保存成功";
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("code","0");
            hashMap.put("msg",msg);
            return hashMap;
        }
        return null;
    }
}
